package com.study.study.quartz;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.concurrent.TimeUnit;

/**
 * 名称：QuartzTest
 * 功能描述：学习quartz框架
 *
 * @author: zhang
 * @version: 3.0
 * @date: 2019-09-08 21:54:43
 * @since 1.8
 **/
public class QuartzTest {

    public static void main(String[] args) {
        try {
            Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
            scheduler.start();
            JobDetail job = JobBuilder.newJob(HelloJob.class)
                    .withIdentity("job1", "group1")
                    .usingJobData("task", "zhangyi")
                    .build();
            Trigger trigger = TriggerBuilder.newTrigger()
                    .withIdentity("trigger1", "group1")
                    .startNow()
                    .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ? *"))
                    .build();

//            JobDetail job2 = JobBuilder.newJob(HelloJob.class)
//                    .withIdentity("job2","group2")
//                    .build();
//            Trigger trigger2 = TriggerBuilder.newTrigger()
//                    .withIdentity("trigger2","group2")
//                    .startNow()
//                    .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ? *"))
//                    .build();
            scheduler.scheduleJob(job, trigger);
//            scheduler.scheduleJob(job2,trigger2);
            TimeUnit.SECONDS.sleep(2000);
            scheduler.shutdown();
        } catch (SchedulerException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}
